<!-- 外链,webview -->
<template>
  <view><web-view ref="webView" :src="webviewPath" @message="handleMessage"></web-view></view>
</template>

<script>
// #ifdef MP
import BestSignFaceUtils from '@/common/bestsign/bestSignFaceUtils'
// #endif
export default {
  data() {
    return {
      businessScene: '',
      webviewPath: '',
    }
  },
  onLoad(options) {
    this.businessScene = options.scene
    this.webviewPath = decodeURIComponent(options.webviewPath)
  },
  onReady() {
    // #ifdef APP-PLUS
    const currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
    // console.info('🚀 ~ onReady ~ currentWebview:', currentWebview)
    setTimeout(() => {
      const wv = currentWebview.children()[0]
      // console.log('🚀 ~ wv:', wv)
      wv.overrideUrlLoading({ mode: 'reject', match: '.*sxj://.*' }, (e) => {
        // console.log('🚀 ~ e:', e)
        const { url } = e
        const path = url.split('sxj:/')[1]
        // console.log('🚀 ~ path:', path)
        uni.redirectTo({ url: path })
      })
    }, 500) //如果是页面初始化调用时，需要延时一下
    // #endif
  },
  methods: {
    getMessage(e) {
      console.log('🚀 ~ getMessage ~ e:', e)
    },

    handleMessage(e) {
      console.log('🚀 ~ handleMessage ~ msgData:', e)
      // #ifdef MP
      switch (this.businessScene) {
        case 'faceAuth':
          const { path } = this.$Route
          const bestSign = new BestSignFaceUtils(path, this.businessScene)
          const receiveH5PageData = e.detail.data[0]
          bestSign._jumpFaceMiniProgram(receiveH5PageData)
          break

        default:
          break
      }
      // #endif
    },
  },
}
</script>

<style></style>
